package com.yy.QSManage.api.gen;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yy.QSManage.api.BaseApi;
import com.yy.QSManage.common.Result;
import com.yy.QSManage.model.entity.FaSysMenu;
import com.yy.QSManage.model.entity.gen.FaSysMenuView;
import com.yy.QSManage.service.gen.FaSysMenuViewService;
import com.yy.QSManage.tool.TreeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/FaSysMenuViewApi")
@Api(tags = "菜单view")
public class FaSysMenuViewApi extends BaseApi<FaSysMenuView>{

    @Autowired
    FaSysMenuViewService menuViewService;

    @ApiOperation("菜单树")
    @GetMapping("/menuTree")
    public Result<List<FaSysMenu>> menuTree() {
        IPage<FaSysMenu> page = menuViewService.page(new Page(1, Integer.MAX_VALUE));
        List<FaSysMenu> list = page.getRecords();
        // 数据转化为树
        list = TreeUtil.build( list);
        return Result.success(list);
    }
}
